﻿var Message = {
    OKFunction: null,
    CancelFunction: null,
    YesFunction: null,
    NoFunction: null
};
// Close MessageBox
Message.Close = function () {
    $('#divMessage').dialog('destroy').remove();
};
//Open MessageBox
Message.Show = function (text, messageBoxButtons, messagetype, defaultButton, param) {

    var iconUrl = './resources/images/information.png';
    //Set icon image
    if (messagetype == Message.MessageType.Confirm) {
        var iconUrl = './resources/images/information.png';
    }
    else if (messagetype == Message.MessageType.Error) {
        var iconUrl = './resources/images/error.png';
    }
    else if (messagetype == Message.MessageType.Warning) {
        var iconUrl = './resources/images/warning.png';
    }

    var div = '<div id="divMessage"> <table><tr><td> <img id="imgicon" src="' + iconUrl + '" alt="Smiley face" height="42" width="42"></td><td> <div id="txtMessage">'+ text +'</div><td></tr></table> </div>';
    var buttons =null;
    //debugger;
    if (messageBoxButtons == Message.MessageBoxButtons.YesNo) {
        buttons = {
            "Yes": function () { Message.Close(); if (Message.YesFunction != null) { Message.YesFunction(); Message.YesFunction = null; } },
            "No": function () { if (Message.NoFunction != null) { Message.NoFunction(); Message.NoFunction = null; } Message.Close(); }

        };
    } else if (messageBoxButtons == Message.MessageBoxButtons.OKCancel) {

        buttons = {
            "OK": function () { if (Message.OKFunction != null) { Message.OKFunction(); Message.OKFunction = null; } Message.Close(); },
            "Cancel": function () { if (Message.CancelFunction != null) { Message.CancelFunction(); Message.CancelFunction = null; } Message.Close(); }
        };
    }
    else if (messageBoxButtons == Message.MessageBoxButtons.YesNoCancel) {
        buttons = {
            "Yes": function () { Message.Close(); if (Message.YesFunction != null) { Message.YesFunction(); Message.YesFunction = null; } },
            "No": function () { if (Message.NoFunction != null) { Message.NoFunction(); Message.NoFunction = null; } Message.Close(); },
            "Cancel": function () { if (Message.CancelFunction != null) { Message.CancelFunction(); Message.CancelFunction = null; } Message.Close(); }
        };
    } else if (messageBoxButtons == Message.MessageBoxButtons.OK) {
        buttons = {
            "OK": function () { if (Message.OKFunction != null) { Message.OKFunction(); Message.OKFunction = null; } Message.Close(); }
        };

    }

    var result = $(div).dialog({

        autoOpen: false,
        width: 400,
        height: 'auto',
        modal: true,
        resizable: false,
        buttons: buttons,
    });
    result.dialog('open');
    //Set title of messagebox
    $('.ui-dialog .ui-dialog-titlebar:last').append(messagetype);

};
Message.MessageBoxButtons = {
    // Summary:
    //     The message box contains an OK button.
    OK: 0,
    //
    // Summary:
    //     The message box contains OK and Cancel buttons.
    OKCancel: 1,
    //
    // Summary:
    //     The message box contains Abort, Retry, and Ignore buttons.
    AbortRetryIgnore: 2,
    //
    // Summary:
    //     The message box contains Yes, No, and Cancel buttons.
    YesNoCancel: 3,
    //
    // Summary:
    //     The message box contains Yes and No buttons.
    YesNo: 4,
    //
    // Summary:
    //     The message box contains Retry and Cancel buttons.
    RetryCancel: 5
};
Message.ButtonValue = {
    OK: 1,
    Cancel: 2,
    Yes: 3,
    No: 4,
    Abort: 5,
    Retry: 6,
    Ignore: 7
};
Message.MessageType =
{
    Warning: "Warning",
    Confirm: "Confirm",
    Error: "Error",
    Information: "Information",
    Question: "Question"
};




